package com.taotao.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.taotao.mapper.TbItemCatMapper;
import com.taotao.po.TbItemCat;
import com.taotao.po.TbItemCatExample;
import com.taotao.po.TbItemCatExample.Criteria;
import com.taotao.pojo.EasyUITreeNote;
import com.taotao.service.ItemCatService;

@Service
public class ItemCatServiceImpl implements ItemCatService{

	@Autowired
	private TbItemCatMapper itemCatMapper;
	
	@Override
	public List<EasyUITreeNote> getItemCatList(long id) {
		TbItemCatExample example=new TbItemCatExample();
		Criteria criteria = example.createCriteria();
		// 添加查询条件
		criteria.andParentIdEqualTo(id);
		List<TbItemCat> itemCatList=itemCatMapper.selectByExample(example);
		EasyUITreeNote treeNote;
		// 创建商品分类树节点List
		List<EasyUITreeNote> list=new ArrayList<EasyUITreeNote>();
		for (TbItemCat tbItemCat : itemCatList) {
			treeNote=new EasyUITreeNote();
			treeNote.setId(tbItemCat.getId());
			treeNote.setText(tbItemCat.getName());
			treeNote.setState(tbItemCat.getIsParent()?"closed":"open");
			list.add(treeNote);
		}
		return list;
	}
}
